(function(){

var role = require("./role");
var BusCon = require("../../core/bus/_con");
var UserCon = require("../../core/user/_con");
var GoodsCon = require("../../core/goods/_con");
var AchCon = require("../../core/ach/_con");
var PayAchCon = require("../../core/pay_ach/_con");
var db = require("../../core/db/index");
var config = require("../../core/_include/config");
var ResponObj = require("../_include/responObj");

module.exports = {
	prefix:"/user/buy",
	get:{
		//.query.ua_id 用户收货地址（可空，使用默认收货地址）
		"/makeach/:goods_id":function (){
			var user  = role.getUser(this);
			var goods_id = this.params.goods_id;
			var ua_id = this.request.query.ua_id;
			var goods = GoodsCon.get(goods_id);
			
			goods.makeAch(goods_id,ua_id)
		},
		"/payach/:ach_id":function (){
			var user  = role.getUser(this);
			var pa_id = user_a.payAch(ach_id);
			this.body = ResponObj("json","进行订单支付");
		},
		"/endpayach/:pa_id":function (){
			var user  = role.getUser(this);
			var pa = PayAchCon.get(pa_id);
			if(pa){
				pa.endPayAch();
				this.body = ResponObj("json","完成支付");
			}else{
				this.body = ResponObj("error","找不到支付信息");
			}
		}
	},
	post:{
		"/":function (){
			this.body = this.request.body;
		}
	}
	//TODO:取消订单
}

}());